import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class ThreadDemo10 {
    public static void main(String[] args) {
        BlockingQueue<Integer> queue = new LinkedBlockingQueue<>();
        Thread customer = new Thread(){
            @Override
            public void run() {
                while (true){
                    try {
                        Integer value = queue.take();
                        System.out.println("消费了: " + value);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        customer.start();

        Thread producer = new Thread(){
            @Override
            public void run() {
                for (int i = 1; i <= 10000; i++) {
                    try {
                        queue.put(i);
                        System.out.println("生产了: "+ i);
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        producer.start();

        try {
            customer.join();
            producer.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}